<template>
  <div class="tab-bar-item" @click="toActive">
    <div v-if="!isActive" ><slot name="item-icon"></slot></div>
    <div v-else ><slot name="item-icon-active"></slot></div>
    <div :class="{'active':isActive}" :style="activeStyle"><slot name="item-text"></slot></div>
  </div>
</template>

<script>
  export default {
    name: "TarbarItem",
    props:{
      path:String,
      activeColor:{
        type:String,
        default:'#ff4500'
      }
    },
    data(){
      return {
      }
    },
    computed:{
      isActive(){
        return this.$route.path.indexOf(this.path)!==-1;
      },
      activeStyle(){
        return this.isActive?{color:this.activeColor}:{}
      }
    },
    methods:{
      toActive(){
        this.$router.replace(this.path).catch(()=>{})
      }
    }
  }
</script>

<style scoped>

  .tab-bar-item{
    flex:1;
    text-align: center;
    height: 40px;
    font-size: 12px;
    color:green;
  }
  .tab-bar-item img{
    width: 16px;
    height: 16px;
    margin-top: 3px;
    margin-bottom: 0px;
    border-radius: 3px;
  }
</style>
